<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Class与style的绑定</title>
    <script src="./js/vue.js"></script>
    <style>
        .actived{
            color: red;
        }
        .actived-one{
            margin-top: 10px;
            padding: 10px;
            background: rgb(216, 192, 240);
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div :class="{actived: isActived}" @click="handleDiv1Click">{{msg}}</div>
        <!-- bind绑定class属性 名称为actived 这个类是否显示取决于isActived变量-->
        <div :class="[actived, activedOne]" @click="handleDiv2Click">{{msg}}</div>
        <!-- 绑定class属性名为actived的变量，该变量一开始为空，后边可以赋值为actived字符串 -->
        <div :style="styleObj" @click="handleDiv3Click">{{msg}}</div>
        <!-- styleObj是一个js的对象变量 -->
        <div :style="[styleObj, {fontSize: '20px'}]" @click="handleDiv3Click">{{msg}}</div>
        <!-- div显示的样式，由数组里的对象所决定 -->
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                msg: "hello vue",
                isActived: false,
                actived: "",
                activedOne: "actived-one",
                styleObj:{
                    color: "black",
                }
            },
            methods: {
                // 使用对象绑定样式
                handleDiv1Click: function(){
                    // 这是我的方法
                    // if(!this.isActived){
                    //     this.isActived = true;
                    // } else {
                    //     this.isActived = false;
                    // }   
                    
                    //这是老师的方法 这就是区别
                    this.isActived = !this.isActived;
                },
                // 使用数组绑定样式
                handleDiv2Click: function(){
                    this.actived = this.actived === "actived" ? "" : "actived";
                },

                // 使用style绑定样式
                handleDiv3Click: function(){
                    this.styleObj.color = this.styleObj.color === "red" ? "black" : "red";
                }
            }
        });
    </script>
</body>
</html>